// pages/my/vip/vip_invitation/component/dialogBox/dialogBox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data:{
      type: Object,
      value: {},
      observer (newVal) {
        this.getData(newVal)
      }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    price: 0,
    payNum:null,
    limitNum: 0,
    totalPrice:0,
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getData(data){
      const price = data.price
      const MaxPayNum = data.num
      let limitNum = (10000/price - MaxPayNum)>0?MaxPayNum:10000/price
      limitNum = limitNum.toFixed(0)

      this.setData({
        price,
        limitNum
      })
    },

    inputNum(e) {
      const payNum = e.detail.value
      let totalPrice = this.data.price * payNum
      console.log(totalPrice);
      this.setData({
        payNum,
        totalPrice
      })
    },
    closeDialog() {
      this.triggerEvent('closeDialog')
    },
    confirm(){
      let payNum = Number(this.data.payNum) 
      const limitNum = this.data.limitNum 
      let totalPrice = this.data.totalPrice 
      if(payNum > limitNum){
        wx.showToast({
          title: '不可超过限购数',
          icon:'none'
        })
        return
      }else if(!payNum){
        payNum = 1
        totalPrice = this.data.price * payNum
      }
      this.triggerEvent('closeDialog')
      this.triggerEvent('createCouponOrder',payNum)


    }

  },
  
})